<?php

/**
 * This is the model class for table "member".
 *
 * The followings are the available columns in table 'member':
 * @property integer $id
 * @property string $username
 * @property string $pass
 * @property string $ip
 * @property string $flag
 *
 * The followings are the available model relations:
 * @property Favorite[] $favorites
 */
class Member extends CActiveRecord
{
	public $pass_repeat;
    /**
     * Returns the static model of the specified AR class.
     * @return Member the static model class
     */
    public static function model($className=__CLASS__)
    {
        return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName()
    {
        return 'member';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules()
    {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
       	 	array('pass', 'compare','compareAttribute'=>'pass_repeat','operator'=>'=','message'=>'<span style="color: #c00">密码有误，请重新输入</span>'),
            array('username, pass, pass_repeat, email', 'required','message'=>'<span style="color: #c00"><b>{attribute}*</b>是必填项目.</span>'),
            array('username, pass, ip', 'length', 'max'=>45,'message'=>'<span style="color: #c00"><b>{attribute}*</b>字数过长</span>'),
            array('email','email','allowEmpty'=>false,'message'=>'<span style="color: #c00">请输入正确邮箱</span>'),
            array('flag', 'length', 'max'=>8),
            array('username', 'unique','message'=>'<span style="color: #c00">用户名已经被占用</span>'),
            
            // The following rule is used by search().
            // Please remove those attributes that should not be searched.
            array('id, username, pass, ip, flag', 'safe', 'on'=>'search'),
        );
    }

    /**
     * @return array relational rules.
     */
    public function relations()
    {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
            'favorites' => array(self::HAS_MANY, 'Favorite', 'member_id'),
        );
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels()
    {
        return array(
            'id' => 'ID',
            'username' => '用户名',
            'pass' => '密码',
        	'pass_repeat' => "密码确认",
        	'email' => '邮箱',
            'ip' => 'Ip',
            'flag' => 'Flag',
        );
    }

    /**
     * Retrieves a list of models based on the current search/filter conditions.
     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
     */
    public function search()
    {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria=new CDbCriteria;

        $criteria->compare('id',$this->id);
        $criteria->compare('username',$this->username,true);
        $criteria->compare('pass',$this->pass,true);
        $criteria->compare('ip',$this->ip,true);
        $criteria->compare('flag',$this->flag,true);

        return new CActiveDataProvider($this, array(
            'criteria'=>$criteria,
        ));
    }
}